/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treeship.core.ship.space.impl;

import treeship.core.ship.space.Distance;
import treeship.core.ship.space.Position;
import treeship.core.ship.space.Speed;

/**
 *
 * @author moonchild
 */
public class Position1D extends Position {

    private double x;

    public Position1D(double x) {
        this.x = x;
    }

    @Override
    public Distance distanceFrom(Position x1) {
        Position1D xx1 = (Position1D) x1;
        return new Distance(Math.abs(getX() - xx1.getX()));
    }

    public double getX() {
        return x;
    }

    @Override
    public String toString() {
        return Math.round(x * 100) / 100.0 + "";

    }

    @Override
    @Deprecated
    public double getY() {
        return 0;
    }

    @Override
    @Deprecated
    public double getZ() {
        return 0;
    }

    @Override
    public Position goFromPositionWithSpeed(Position fromPosition, Speed speed) {
        Position1D from = (Position1D) fromPosition;
        if (distanceFrom(from).getValue() <= speed.getValue()) {
            return this;
        }

        if (x < from.getX()) {
            return new Position1D(from.getX() - speed.getValue());
        }

        return new Position1D(from.getX() + speed.getValue());

    }
}
